package cn.tedu.luban.demand.main.repository;

import cn.tedu.luban.demand.main.converter.DemandConverter;
import cn.tedu.luban.demand.main.dao.DemandDAO;
import cn.tedu.luban.demand.protocol.bo.RequestOrderBO;
import cn.tedu.luban.demand.protocol.dos.RequestOrderDO;
import cn.tedu.luban.demand.protocol.param.GrabOrderParam;
import cn.tedu.luban.demand.protocol.query.RequestOrderDBPagerQuery;
import cn.tedu.luban.demand.protocol.query.RequestOrderQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class DemandRepoImpl  implements  DemandRepository{

    @Autowired
    private DemandDAO demandDAO;
    @Autowired
    private DemandConverter demandConverter;

    @Override
    public Long getRequestOrderCount(RequestOrderQuery requestOrderQuery) {
        // 分页查询
        RequestOrderDBPagerQuery pagerQuery =
                demandConverter.toDbPagerQuery(requestOrderQuery);
        // 查询总数
        return demandDAO.countRequestOrder(pagerQuery);
    }

    @Override
    public List<RequestOrderBO> queryRequestOrders(RequestOrderQuery requestOrderQuery) {
        // 分页查询
        RequestOrderDBPagerQuery pagerQuery =
                demandConverter.toDbPagerQuery(requestOrderQuery);
        // list分页
        List<RequestOrderDO> dos = demandDAO.queryRequestOrders(pagerQuery);

        return demandConverter.poList2BoList(dos);
    }

    @Override
    public Integer grabOrder(GrabOrderParam grabOrderParam) {
        return null;
    }

    @Override
    public RequestOrderBO getRequestOrder(String requestOrderNo) {
        return null;
    }

    @Override
    public Integer returnOrder(GrabOrderParam requestOrderNo) {
        return null;
    }

    @Override
    public Integer grabOrder(String requestOrderNo) {

        RequestOrderDO requestOrderDO = new RequestOrderDO();
        requestOrderDO.setRequestOrderNo(requestOrderNo);
        requestOrderDO.setGrabStatus(0);

        return demandDAO.updateGrabStatusByOrderNo(requestOrderDO);
    }

    @Override
    public Integer returnOrder(String requestOrderNo) {
        RequestOrderDO requestOrderDO = new RequestOrderDO();
        requestOrderDO.setRequestOrderNo(requestOrderNo);
        requestOrderDO.setGrabStatus(1);

        return demandDAO.updateGrabStatusByOrderNo(requestOrderDO);
    }

    @Override
    public RequestOrderBO getRequestOrderGrabed(String no) {
        return null;
    }
}
